namespace SinaFinanceBaseClassLibrary
{
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Shapes;

    public class TimeSharingCrossLine
    {
        private List<IntersectionPointInfoArea> areas = new List<IntersectionPointInfoArea>();
        private int controlZindex = 10;
        private Image coreImage = new Image();
        private Line crossLine1 = new Line();
        private Line crossLine2 = new Line();
        private Line crossLine3 = new Line();
        private string dateTime = string.Empty;
        private List<Point> intersectionPoint = new List<Point>();
        private IntersectionPointInfoArea intersectionPointInfoArea = new IntersectionPointInfoArea();
        private Canvas parentCanvas;
        private Point pointLeftBottom = new Point();
        private Point pointLeftTop = new Point();
        private Point pointRightTop = new Point();
        private string price = string.Empty;
        private string stockId = string.Empty;
        private string stockName = string.Empty;
        private List<TimeSharingPoint> timeSharingPoints = new List<TimeSharingPoint>();

        public void DrawCrossLine(string stockInfo)
        {
            if (!this.intersectionPoint.Count.Equals(0) && ((this.timeSharingPoints != null) && !this.timeSharingPoints.Count.Equals(0)))
            {
                this.RemoveCrossLine();
                Point point = new Point(this.pointLeftTop.X, this.intersectionPoint[0].Y);
                Point point2 = new Point(this.pointRightTop.X, this.intersectionPoint[0].Y);
                Point point3 = new Point(this.intersectionPoint[0].X, this.pointLeftTop.Y);
                Point point4 = new Point(this.intersectionPoint[0].X, this.pointLeftBottom.Y);
                this.crossLine1.X1 = point.X;
                this.crossLine1.Y1 = point.Y;
                this.crossLine1.X2 = point2.X;
                this.crossLine1.Y2 = point2.Y;
                this.crossLine3.X1 = point3.X;
                this.crossLine3.Y1 = point3.Y;
                this.crossLine3.X2 = point4.X;
                this.crossLine3.Y2 = point4.Y;
                this.crossLine1.Stroke = new SolidColorBrush(Colors.Red);
                this.crossLine3.Stroke = new SolidColorBrush(Colors.Red);
                this.crossLine1.StrokeThickness = 1.0;
                this.crossLine3.StrokeThickness = 1.0;
                this.crossLine1.StrokeDashArray.Add(2.0);
                this.crossLine3.StrokeDashArray.Add(2.0);
                this.crossLine1.SetValue(Canvas.ZIndexProperty, this.controlZindex);
                this.crossLine3.SetValue(Canvas.ZIndexProperty, this.controlZindex);
                this.parentCanvas.Children.Add(this.crossLine1);
                this.parentCanvas.Children.Add(this.crossLine3);
                for (int i = this.areas.Count - 1; i > -1; i--)
                {
                    this.areas[i].RemoveIntersectionPointInfoArea();
                }
                this.intersectionPointInfoArea.StockId = stockInfo;
                this.intersectionPointInfoArea.DateTime = this.timeSharingPoints[0].XInfo.Equals("13:00:00") ? "11:30:00" : this.timeSharingPoints[0].XInfo;
                this.intersectionPointInfoArea.Price = this.timeSharingPoints[0].YInfo;
                this.intersectionPointInfoArea.Volumn = this.timeSharingPoints[0].VolumnInfo;
                this.intersectionPointInfoArea.ParentCanvas = this.parentCanvas;
                this.intersectionPointInfoArea.AppendIntersectionPointInfoArea();
                if (!this.areas.Contains(this.intersectionPointInfoArea))
                {
                    this.areas.Add(this.intersectionPointInfoArea);
                }
                this.coreImage.SetValue(Canvas.ZIndexProperty, this.controlZindex);
                this.parentCanvas.Children.Add(this.coreImage);
                this.coreImage.Margin = new Thickness(this.intersectionPoint[0].X - 4.5, this.intersectionPoint[0].Y - 4.5, 0.0, 0.0);
                if ((this.intersectionPoint != null) && (this.intersectionPoint.Count > 1))
                {
                    Point point5 = new Point(this.pointLeftTop.X, this.intersectionPoint[1].Y);
                    Point point6 = new Point(this.pointRightTop.X, this.intersectionPoint[1].Y);
                    this.crossLine2.X1 = point5.X;
                    this.crossLine2.Y1 = point5.Y;
                    this.crossLine2.X2 = point6.X;
                    this.crossLine2.Y2 = point6.Y;
                    this.crossLine2.StrokeThickness = 0.7;
                    this.crossLine2.StrokeDashArray.Add(2.0);
                    this.crossLine2.Stroke = new SolidColorBrush(Colors.Red);
                    this.parentCanvas.Children.Add(this.crossLine2);
                }
            }
        }

        public void RemoveCrossLine()
        {
            if (this.parentCanvas != null)
            {
                if (this.parentCanvas.Children.Contains(this.crossLine1))
                {
                    this.parentCanvas.Children.Remove(this.crossLine1);
                }
                if (this.parentCanvas.Children.Contains(this.crossLine2))
                {
                    this.parentCanvas.Children.Remove(this.crossLine2);
                }
                if (this.parentCanvas.Children.Contains(this.crossLine3))
                {
                    this.parentCanvas.Children.Remove(this.crossLine3);
                }
                this.parentCanvas.Children.Remove(this.coreImage);
                for (int i = this.areas.Count - 1; i > -1; i--)
                {
                    this.areas[i].RemoveIntersectionPointInfoArea();
                }
            }
        }

        public int ControlZindex
        {
            get
            {
                return this.controlZindex;
            }
            set
            {
                this.controlZindex = value;
            }
        }

        public Image CoreImage
        {
            get
            {
                return this.coreImage;
            }
            set
            {
                this.coreImage = value;
            }
        }

        public List<Point> IntersectionPoint
        {
            get
            {
                return this.intersectionPoint;
            }
            set
            {
                this.intersectionPoint = value;
            }
        }

        public Canvas ParentCanvas
        {
            get
            {
                return this.parentCanvas;
            }
            set
            {
                this.parentCanvas = value;
            }
        }

        public Point PointLeftBottom
        {
            get
            {
                return this.pointLeftBottom;
            }
            set
            {
                this.pointLeftBottom = value;
            }
        }

        public Point PointLeftTop
        {
            get
            {
                return this.pointLeftTop;
            }
            set
            {
                this.pointLeftTop = value;
            }
        }

        public Point PointRightTop
        {
            get
            {
                return this.pointRightTop;
            }
            set
            {
                this.pointRightTop = value;
            }
        }

        public List<TimeSharingPoint> TimeSharingPoints
        {
            get
            {
                return this.timeSharingPoints;
            }
            set
            {
                this.timeSharingPoints = value;
            }
        }
    }
}
